using System;
using System.Data;
using System.Drawing;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Dimok.Web.UI;
using Data;

namespace Dimok.Aspx.Manager.Lib.Controls {
	public partial class Borrower : UserControlClientSafe {
		public byte BorrowerPosition = 255;
		protected void Page_Load(object sender, System.EventArgs e) {
			UOX uox = ((Page_AL)this.Page).uox;
			XmlAttrs.InnerHtml = SQL.MakeDSXml("pos",BorrowerPosition);
			DataSet dsBorrower = uox.ApplInfo.Borrower(BorrowerPosition);
			int borrowerID = dsBorrower.Tables[0].Rows.Count > 0 ? (int)dsBorrower.Tables[0].Rows[0]["ID"] : -1;
			XmlBorrower.InnerHtml = SQL.XmlInnerText(dsBorrower);
			int addrCount = uox.ApplInfo.AddressCount(borrowerID);
			for( byte a=0; a < addrCount; a++ ){
				Lib.Controls.Address ctlAddress = (Lib.Controls.Address)LoadControl("/manager/lib/controls/Address.ascx");
				ctlAddress.BorrowerID = borrowerID;
				ctlAddress.AddressPosition = a;
				pnlAddress.Controls.Add(ctlAddress);
			}
			int emplCount = uox.ApplInfo.EmploymentCount(borrowerID);
			for( byte a=0; a < emplCount; a++ ){
				Lib.Controls.Employment ctlEmpl = (Lib.Controls.Employment)LoadControl("/manager/lib/controls/Employment.ascx");
				ctlEmpl.BorrowerID = borrowerID;
				ctlEmpl.EmploymentPosition = a;
				pnlEmployment.Controls.Add(ctlEmpl);
			}

			Lib.Controls.PhoneVerifications ctlPhoneVers = (Lib.Controls.PhoneVerifications)LoadControl("/manager/lib/controls/PhoneVerifications.ascx");
			ctlPhoneVers.BorrowerID = borrowerID;
			pnlReferences.Controls.Add(ctlPhoneVers);

			Lib.Controls.References ctlRefs = (Lib.Controls.References)LoadControl("/manager/lib/controls/References.ascx");
			ctlRefs.BorrowerID = borrowerID;
			pnlReferences.Controls.Add(ctlRefs);

			SQL.SELECT(selLanguage,uox.db,"SELECT ID,Name FROM ts_Language","Name","ID");
			Literal lit = new Literal();
			lit.Text = "<script>var XmlAttrs = " + XmlAttrs.ClientID + ";</script>";
			Controls.AddAt(Controls.IndexOf(XmlAttrs) + 1, lit);
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e) {
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent() {
		}
		#endregion
	}
}
